from pathlib import Path
from tkinter import filedialog
from tkinter import *
from birch import *

root = Tk()

current_dir = Path.cwd() 

root.geometry('{}x{}'.format(400,60))
canvas = Canvas(root,width=395,height=55)
canvas.pack()

lbl1 = Label(canvas, text="Text = ") 
lbl1.grid(column=0, row=0) 

txt1 = Entry(canvas,width=42, foreground="white", background="black")  
txt1.grid(column=1, row=0) 

def clicked1():
    M = str.encode(txt1.get()) # str -> bytes
    #print(type(M))
    #birch_code_encode(M).save("output.png")
    filename = filedialog.asksaveasfilename(initialdir = current_dir, 
								title = "Select imagefile", filetypes = (("png files", "*.png"),("all files", "*.*")), defaultextension=".png")
    out_img = birch_code_encode(M).save(filename)

btn1 = Button(canvas, text="encode", command=clicked1)
btn1.grid(column=2, row=0)

def clicked2():
	filename = filedialog.askopenfilename(initialdir = current_dir, 
										title = "Select imagefile", filetypes = (("png files", "*.png"), ("JPG files", "*.JPG"),("jpeg files", "*.jpeg"),
 										("jpg files", "*.jpg"),
 										("bmp files", "*.bmp"),("all files", "*.*")))
	print(birch_code_decode(filename).decode("utf-8") )

btn2 = Button(canvas, text="decode", command=clicked2, width=17)
btn2.grid(column=1, row=3)
		
root.mainloop()